package com.hyjx.framework.common;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

/**
 * 属性对象工具类，可用于读取配置文件
 *
 * @author dijian
 */
public class PropertyUtil {
    private static Properties globalProp = new OrderedProperties();

    static {
        loadGlobal();
    }

    /**
     * 返回属性信息对象
     *
     * @return
     */
    public static Properties getGlobalObj() {
        return globalProp;
    }

    public static void loadGlobal() {
        try {
            InputStream is = PropertyUtil.class.getResourceAsStream("/application.properties");
            globalProp.clear();
            globalProp.load(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 取配置信息
     *
     * @param key
     * @return
     */
    public static String getValue(String key) {
        String value = (String) globalProp.get(key);
        if (value != null) {
            value = value.trim();
            try {
                value = new String(value.getBytes("iso8859-1"), "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return value;
    }
}